package org.bedracket.bedracketenchantment.enchantment;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.bedracket.bedracketenchantment.init.ModEnchantments;

public class VampirismEnchantment extends Enchantment {
    public VampirismEnchantment() {
        super(Rarity.RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
    }

    @Override
    public int getMaxLevel() {
        return 3;
    }

    @Override
    public int getMinCost(int level) {
        return 1 + (level - 1) * 11;
    }

    @Override
    public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) {
        ItemStack stack = pAttacker.getMainHandItem();
        int vampirismLevel =
                EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.VAMPIRISM.get(), stack);
        if (vampirismLevel > 0 && pAttacker.getHealth() < pAttacker.getMaxHealth()) {
            pAttacker.heal(pAttacker.getHealth() + 1.0f
                    * vampirismLevel);
        }
    }
}
